package com.kaifamiao.queue;

import java.util.LinkedList;
import java.util.List;
import java.util.Queue;

/**
 * 1、java.util.Queue 接口继承了 java.util.Collection 接口
 * 2、操作队列的方法: add(E) 、element() 、remove()
 */
public class QueueTest2 {

	public static void main(String[] args) {
		
		Queue<String> q = new LinkedList<>();
		
		q.addAll( List.of( "顺治" , "康熙" , "雍正" , "乾隆" ) );
		
		System.out.println( q.toString() );
		
		q.add( "嘉庆" );
		System.out.println( q.toString() );
		
		String head  = q.element();// 检查队列头部元素(但不删除)
		System.out.println( head ); 
		System.out.println( q.toString() );
		
		head = q.remove(); // 删除队列头部元素(并返回被删除的元素)
		System.out.println( head ); 
		System.out.println( q.toString() );
		
		head = q.remove(); // 删除队列头部元素(并返回被删除的元素)
		System.out.println( head ); 
		System.out.println( q.toString() );
		
		head = q.remove(); // 删除队列头部元素(并返回被删除的元素)
		System.out.println( head ); 
		System.out.println( q.toString() );
		
		head = q.remove(); // 删除队列头部元素(并返回被删除的元素)
		System.out.println( head ); 
		System.out.println( q.toString() );
		
		head = q.remove(); // 删除队列头部元素(并返回被删除的元素)
		System.out.println( head ); 
		System.out.println( q.toString() );
		
		// head = q.element(); // 若队列为空则抛出NoSuchElementException
		// head = q.remove(); // 若队列为空则抛出NoSuchElementException

	}

}
